--[[ Copyright (C) 2012-2015 Alundaio This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License Callback and module manager for easy plug-in based script management by Alundaio 1/31/2016 axr_main now auto-executes any script that has on_game_load method. To create a new module, simply add a on_game_start function --]] -- axr_options.ini config = ini_file_ex("axr_options.ltx",true) -- load default rspec when axr_options created first time if not (config:section_exist("temp")) then get_console():execute("cfg_load " .. getFS():update_path('$game_config$', '').."rspec_default.ltx") config:w_value("temp","rspec_default",true) config:save() end ------------------------------------------------------------------------------------------------- -- debug scan/simulation function check_on_launch() --get_console():execute("clear_log") -- Simulation --treasure_manager.simulate_stash_creation(700) --death_manager.simulate_death_drops(10) --xrs_rnd_npc_loadout.simulate_npc_loadouts(20,nil,nil,{"primary","secondary"}) -- Generating --itms_manager.generate_boosters_list() -- Others --z_xml_calculator.start() --z_generate_prefetch.start() end check_on_launch() -- ------------------------------------------------------------------------------------------------- -- Valid Callbacks (named intercepts to avoid namespace conflicts) -- You must register a callback before or during on_game_load (ie. bind_actor net_spawn) -- All unused callbacks will have their table deleted from intercepts (see on_game_load for implementation) local intercepts = { --// Player on_before_level_changing = {}, -- Params: () on_level_changing = {}, -- Params: () actor_on_before_death = {}, -- Params: (,) actor_on_net_destroy = {}, -- Params: () actor_on_first_update = {}, -- Params: (,) actor_on_update = {}, -- Params: (,) actor_on_weapon_fired = {}, -- Params: (,,,,,) actor_on_weapon_jammed = {}, -- Params: () actor_on_weapon_no_ammo = {}, -- Params: (,) actor_on_weapon_lower = {}, -- Params: () actor_on_weapon_raise = {}, -- Params: () actor_on_weapon_reload = {}, -- Params: (,) actor_on_weapon_zoom_in = {}, -- Params: () actor_on_weapon_zoom_out = {}, -- Params: () actor_on_item_take = {}, -- Params: () actor_on_item_take_from_box = {}, -- Params: (,) actor_on_item_put_in_box = {}, -- Params: (,) actor_on_item_drop = {}, -- Params: () actor_on_item_use = {}, -- Params: (,) actor_on_item_before_use = {}, -- Params: (,
) actor_on_item_before_pickup = {}, -- Params: (,
) actor_item_to_belt = {}, -- Params: () actor_item_to_ruck = {}, -- Params: () actor_item_to_slot = {}, -- Params: () actor_on_trade = {}, -- Params: (,,) actor_on_init = {}, -- Params: () actor_on_reinit = {}, -- Params: () -- actor_on_torch_enabled = {}, -- TODO: Export from engine instead -- actor_on_torch_disabled = {}, -- TODO: Export from engine instead actor_on_info_callback = {}, -- Params: (,) actor_on_hit_callback = {}, -- Params: (,,,,) actor_on_attach_vehicle = {}, -- Params: () actor_on_detach_vehicle = {}, -- Params: () actor_on_use_vehicle = {}, -- Params: () actor_on_hud_animation_play = {}, -- Params: (
,) actor_on_hud_animation_end = {}, -- Params: (,,,,) actor_on_hud_animation_mark = {}, -- Params: (,) actor_on_sleep = {}, -- Params: () actor_on_foot_step = {}, -- Params: (,,,,) actor_on_interaction = {}, -- Params: (,,) actor_on_before_hit = {}, -- Params: (,,,
) actor_on_before_hit_belt = {}, -- Params: (
,,) actor_on_weapon_before_fire = {}, -- Params: (
) actor_on_feeling_anomaly = {}, -- Params: (,
) actor_on_leave_dialog = {}, -- Params: () actor_on_stash_create = {}, -- Params: (
) actor_on_stash_remove = {}, -- Params: (
) actor_on_frequency_change = {}, -- Params: (,) actor_on_achievement_earned = {}, -- Params: (,) actor_on_movement_changed = {}, -- Params: () actor_on_footstep = {}, -- Params: (,,,
) actor_on_jump = {}, -- Params: () actor_on_land = {}, -- Params: () actor_on_before_throwable_select = {}, -- Params: (
) --// NPCs npc_on_use = {}, -- Params: (,) npc_on_choose_weapon = {}, -- Params: (,,
) npc_on_item_take = {}, -- Params: (,) npc_on_item_take_from_box = {}, -- Params: (,,) npc_on_item_drop = {}, -- Params: (,) npc_on_net_spawn = {}, -- Params: (,) npc_on_net_destroy = {}, -- Params: () npc_on_update = {}, -- Params: (,
) npc_on_before_hit = {}, -- Params: (,,,
) npc_on_hit_callback = {}, -- Params: (,,,,) npc_on_death_callback = {}, -- Params: (,) npc_on_fighting_actor = {}, -- Params: () npc_on_weapon_strapped = {}, -- Params: (,) npc_on_weapon_unstrapped = {}, -- Params: (,) npc_on_weapon_drop = {}, -- Params: (,) npc_on_hear_callback = {}, -- Params: (,,,,,) npc_on_get_all_from_corpse = {}, -- Params: (,,,) npc_on_eval_danger = {}, -- Params: (,
) npc_shot_dispersion = {}, -- Params: (,,,,
) anomaly_on_before_activate = {}, -- Params: (,) --// Mutants monster_on_update = {}, -- Params: (,
) monster_on_before_hit = {}, -- Params: (,,,
) monster_on_hit_callback = {}, -- Params: (,,,,) monster_on_net_spawn = {}, -- Params: (,) monster_on_net_destroy = {}, -- Params: () monster_on_death_callback = {}, -- Params: (,) monster_on_actor_use_callback = {}, -- Params: (,) monster_on_loot_init = {}, -- Params: (,
) burer_on_before_weapon_drop = {}, -- Params: (,) --// Physical objects physic_object_on_hit_callback = {}, -- Params: (,,,,) physic_object_on_use_callback = {}, -- Params: (,) --// Vehicles heli_on_hit_callback = {}, -- Params: (,,,,) vehicle_on_death_callback = {}, -- Params: () --// Squads squad_on_npc_creation = {}, -- Params: (,,) squad_on_enter_smart = {}, -- Params: (,) squad_on_leave_smart = {}, -- Params: (,) squad_on_npc_death = {}, -- Params: (,,) squad_on_update = {}, -- Params: () squad_on_first_update = {}, -- Params: () squad_on_add_npc = {}, -- Params: (,,,,,) -- squad_on_register = {}, -- use server_entity_on_register check "sim_squad_scripted" as type_name -- squad_on_unregister = {}, -- use server_entity_on_unregister --[[ WARNING!!!!!: the following 2 callbacks will ALWAYS fire on level change/loaded save because the old data isn't saved for compatibility purpose it's up to the user to check for the case in which old level name/old game vertex is nil in their code if they want to use this ]] squad_on_after_game_vertex_change = {}, -- Params: (,,,) squad_on_after_level_change = {}, -- Params: (,,) --// smart_terrain.script smart_terrain_on_update = {}, -- Params: () on_try_respawn = {}, -- Params: (,
) --// Server objects server_entity_on_register = {}, -- Params: (,) server_entity_on_unregister = {}, -- Params: (,) fill_start_position = {}, -- Params: () se_stalker_on_spawn = {}, -- Params: () -- se_actor_on_register = {}, -- use server_entity_on_register check "se_actor" as type_name -- se_actor_on_unregister = {}, -- use server_entity_on_unregister se_actor_on_STATE_Write = {}, -- Params: () se_actor_on_STATE_Read = {}, -- Params: () --// GUI ActorMenu_on_before_init_mode = {}, -- Params: (,
,) ActorMenu_on_mode_changed = {}, -- Params: (,) ActorMenu_on_item_drag_drop = {}, -- Params: (,,,) ActorMenu_on_item_focus_receive = {}, -- Params: () ActorMenu_on_item_focus_lost = {}, -- Params: () ActorMenu_on_item_before_move = {}, -- Params: (
,,,,,) ActorMenu_on_item_after_move = {}, -- Params: (,,,,) ActorMenu_on_trade_started = {}, -- Params: () ActorMenu_on_trade_closed = {}, -- Params: () GUI_on_show = {}, -- Params: (,) GUI_on_hide = {}, -- Params: (,) map_spot_menu_add_property = {}, -- Params: (,,,) map_spot_menu_property_clicked = {}, -- Params: (,,,) main_menu_on_keyboard = {}, -- Params: (,,,) main_menu_on_init = {}, -- Params: () -- main_menu_on_init_callbacks = {}, main_menu_on_quit = {}, -- Params: () on_screen_resolution_changed = {}, -- Params: () --// Technical on_game_load = {}, -- Params: () on_key_press = {}, -- Params: () on_key_release = {}, -- Params: () on_key_hold = {}, -- Params: () on_before_key_press = {}, -- Params: (,,,
) on_before_key_release = {}, -- Params: (,,,
) on_before_key_hold = {}, -- Params: (,,,
) on_option_change = {}, -- Params: () on_localization_change = {}, -- Params: () on_console_execute = {}, -- Params: (,,,...) command parts on_before_save_input = {}, -- Params: (,,
) on_before_load_input = {}, -- Params: (,,
) --// Files save_state = {}, -- Params: (
) load_state = {}, -- Params: (
) on_pstor_save_all = {}, -- Params: (,) on_pstor_load_all = {}, -- Params: (,) --// Others on_enemy_eval = {}, -- Params: (,,
) on_before_surge = {}, -- Params: (
) on_before_psi_storm = {}, -- Params: (
) on_get_item_cost = {}, -- look at bottom of utils_item.script for detailed explanation bullet_on_hit = {}, -- Params: (,,,,,,) } ----------------------------------------------------------- -- Global Callback Register -- param 1 - name as type (ie. intercepts[name]) -- param 2 - function to execute as type or userdata with name as function ----------------------------------------------------------- function callback_add(name) if (not intercepts[name]) then intercepts[name] = {} else printf("![axr_main callback_add] callback %s already exists!",name) callstack() end end function callback_set(name,func_or_userdata) if (func_or_userdata == nil) then printf("![axr_main callback_set] trying to set callback %s to nil function!",name) callstack() return end if (intercepts[name]) then intercepts[name][func_or_userdata] = true else printf("![axr_main callback_set] callback %s doesn't exist!",name) callstack() end end function callback_unset(name,func_or_userdata) if (intercepts[name]) then intercepts[name][func_or_userdata] = nil else printf("![axr_main callback_unset] callback %s doesn't exist!",name) callstack() end end function make_callback(name,...) if (intercepts[name]) then for func_or_userdata,v in pairs(intercepts[name]) do if (type(func_or_userdata) == "function") then func_or_userdata(...) elseif (func_or_userdata[name]) then func_or_userdata[name](func_or_userdata,...) end end else printf("![axr_main make_callback] can't make callback to non existing intercept %s!",name) callstack() end end -------------------------------------------------------------------------------------------------------------------- -- ON GAME START -------------------------------------------------------------------------------------------------------------------- function on_game_start() local ignore = { ["_G.script"] = true, ["class_registrator.script"] = true, ["game_registrator.script"] = true, ["ui_registrator.script"] = true, ["ce_new_attachable_item.script"] = true, ["ce_new_game_dm.script"] = true, ["sim_faction_brain_human.script"] = true, ["sim_faction_brain_mutant.script"] = true, ["ce_switcher.script"] = true, ["axr_main.script"] = true, ["lua_help.script"] = true, ["rx_gl.script"] = true } local t = {} local size_t = 0 local f = getFS() local flist = f:file_list_open_ex("$game_scripts$",bit_or(FS.FS_ListFiles,FS.FS_RootOnly),"*.script") local f_cnt = flist:Size() for it=0, f_cnt-1 do local file = flist:GetAt(it) local file_name = file:NameShort() --printf("%s size=%s",file_name,file:Size()) if (file:Size() > 0 and ignore[file_name] ~= true) then file_name = file_name:sub(0,file_name:len()-7) if (_G[file_name] and _G[file_name].on_game_start) then size_t = size_t + 1 t[size_t] = file_name -- load all scripts first end end end for i=1,#t do --printf("%s.on_game_start()",t[i]) _G[ t[i] ].on_game_start() end end ------------------ -- main_menu_on_init() ------------------ function main_menu_on_init(menu) xrs_dyn_music.main_menu_on(menu) end ------------------ -- main_menu_on_quit() ------------------ function main_menu_on_quit(menu) xrs_dyn_music.main_menu_off(menu) end function actor_on_weapon_zoom_in() local wpn = db.actor:active_item() scoped_weapon_is_zoomed = wpn and IsWeapon(wpn) and wpn:weapon_is_scope() binoc_is_zoomed = wpn and (wpn:section() == "wpn_binoc_inv") weapon_is_zoomed = true SendScriptCallback("GUI_on_show", "UIZoom") -- to force hiding HUD UIs on Zooming end function actor_on_weapon_zoom_out() scoped_weapon_is_zoomed = false binoc_is_zoomed = false weapon_is_zoomed = false SendScriptCallback("GUI_on_hide", "UIZoom") -- to force hiding HUD UIs on Zooming end ------------------ -- server_entity_on_register ------------------ function server_entity_on_register(se_obj,type_name) local id = se_obj.id if (id == AC_ID) then story_objects.register(id,"actor") else story_objects.check_spawn_ini_for_story_id(se_obj) end end ------------------ -- server_entity_on_unregister ------------------ -- good place to remove ids from persistent tables function server_entity_on_unregister(se_obj,type_name) local id = se_obj.id local m_data = alife_storage_manager.get_state() if (m_data) then if (m_data.se_object) then m_data.se_object[id] = nil --printf("$ alife_storage | cleaning server object [%s](%s) mdata", se_obj:name(), id) end if (m_data.game_object) then m_data.game_object[id] = nil --printf("$ alife_storage | cleaning game object [%s](%s) mdata", se_obj:name(), id) end end story_objects.unregister(id) end